home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue26 / websol / main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-15  |  3.8 KB  |  103 lines

  1. unit main;
  2. // This example program is very simple.  Randomly select a number between 1
  3. // and 100, ask the user to guess it.  Respond with high or low until the
  4. // user gets it right, then respond with confirmation and a count of how
  5. // many tries it took.
  6. // Most importantly, it shows one way to make the data persistent in the
  7. // disconnected environment of the user proxy mode.
  8. interface
  9.  
  10. uses
  11.     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  12.     htmler, StdCtrls;
  13.  
  14. type
  15.     TformMain = class(TForm)
  16.         IAG_Region1: TIAG_Region;
  17.         Label1: TLabel;
  18.         lablResponse: TLabel;
  19.         editGuess: TEdit;
  20.     butnGuess: TIAG_Button;
  21.     Variables: TIAG_Variables;
  22.     intvMagicNo: TIntegerVar;
  23.     intvGuessCount: TIntegerVar;
  24.     Label2: TLabel;
  25.     lablCount: TLabel;
  26.     StringVar1: TStringVar;
  27.         procedure butnGuessClick(Sender: TObject);
  28.         procedure FormCreate(Sender: TObject);
  29.     procedure IAG_Region1AfterShow(Sender: TObject);
  30.     private
  31.     public
  32.     end;
  33.  
  34. var
  35.     formMain: TformMain;
  36.  
  37. implementation
  38. {$R *.DFM}
  39.  
  40. Uses
  41.     //Required for access to the iagin object when designing forms which require
  42.     //     interaction beyond display and click on link capabilities
  43.     IAG_Server_Info;
  44.  
  45. procedure TformMain.butnGuessClick(Sender: TObject);
  46.  
  47. // Buttons, DBNavigators, and Tabs cause a submit to occur.  In Web terms, this
  48. // causes the browser to respond back to the server with the HTML variables and
  49. // through Portcullis, fires the appropriate click event.  As a result, Buttons, Tabs,
  50. // and DBNavigators work as though you were just in the Delphi environment.
  51. // Other "click event" items are not currently supported as Click Events.
  52. // They are functional in every other way such that you can reference their
  53. // properties as usual.  One exception to this is the 'disable' property which
  54. // would normally 'grey-out' a check box, is not currently supported. The
  55. // suggestion is to 'hide' it instead.  In general, click events are not
  56. // supported as the environment is on the client machine (in the browser) until
  57. // one of the three supported events (above) occur, but most properties are supported.
  58.  
  59. var
  60.     iUserInput: Integer;
  61. begin
  62.     butnGuess.Form := '';
  63.     lablResponse.Visible := False;
  64.  
  65.     if intvMagicNo.value = -1 then intvMagicNo.value := Random(100) + 1;
  66.  
  67.     // Variables which are associated with EditBox's, radio buttons, check boxes
  68.     // etc, are handled just as if you are still in the Delphi environment.
  69.     // NO SPECIAL HANDLING REQUIRED.
  70.  
  71.     // Mesgbox is a procedure included with WSB which allows use of the mesgbox
  72.     // procedure deployed on the web.  The purpose of this is to allow creation
  73.     // of a web page to deliver a message (like a modal dialog without the
  74.     // buttons). The functionality of buttons can be implemented as links.
  75.     // Use this in place of application.messagebox and/or showmessage
  76.     // and/or messagedlg to deliver information.
  77.     iUserInput := StrToIntDef(editGuess.Text, -1);
  78.     if (iUserInput < 1) or (iUserInput > 100) then
  79.         MesgBox('You entered an invalid number. Please go back and try again.', '', '', '')
  80.     else if intvMagicNo.value = iUserInput then
  81.         MesgBox('You guessed it! It took you ' + intvGuessCount.AsString + ' guesses.'
  82.          , 'Play another game', iagin.URLToForm('Main', '',''), '')
  83.     else begin
  84.         lablCount.Caption := IntToStr(StrToIntDef(lablCount.Caption, 0) + 1);
  85.         butnGuess.Form := 'Self';
  86.         if iUserInput < intvMagicNo.value then    lablResponse.Caption := IntToStr(iUserInput) + ' is too low.'
  87.             else lablResponse.Caption := IntToStr(iUserInput) + ' is too high.';
  88.         lablResponse.Visible := True;
  89.     end;
  90. end;
  91.  
  92. procedure TformMain.FormCreate(Sender: TObject);
  93. begin
  94.     Randomize;
  95. end;
  96.  
  97. procedure TformMain.IAG_Region1AfterShow(Sender: TObject);
  98. begin
  99.     lablResponse.Caption := '';
  100. end;
  101.  
  102. end.
  103.